package com.diankangwo.dao.impl;

import com.diankangwo.dao.DiscussDAO;
import com.diankangwo.domain.Discuss;
import com.diankangwo.util.PageSupport;
import org.springframework.stereotype.Repository;

@Repository
public class DiscussDAOImpl extends BaseDaoImpl<Discuss> implements DiscussDAO {

    @Override
    public PageSupport<Discuss> getUserByUid(int commodityId, int pageNo, int pageSize, int type) {
        PageSupport<Discuss> blList = new PageSupport<>();
        String hql = "from Discuss where commodityId = ? ";
        if (type == 1) {
            hql += " and evaluate = 1";
        } else if (type == 2) {
            hql += " and evaluate = 2";
        } else if (type == 3) {
            hql += " and evaluate = 0";
        } else if (type == 4) {
            hql += " and pic != null";
        }
        blList = findPagination(hql, pageNo, pageSize, commodityId);
        if (blList == null || blList.getResultData().size() == 0) {
            return null;
        } else {
            return blList;
        }
    }
}
